//
//  TravelsAuthor _HeadView.m
//  艾听歌
//
//  Created by dllo on 16/5/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TravelsAuthor _HeadView.h"

#define ViewW self.frame.size.width
#define ViewH self.frame.size.height


@implementation TravelsAuthor__HeadView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self createSubViews];
        
    }
    
    return self;
}


- (void)createSubViews{
    
    self.headPortraitImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, ViewH / 3 * 2 - 15, ViewH / 3 * 2 - 15)];
    self.headPortraitImageView.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.headPortraitImageView];
    self.headPortraitImageView.layer.masksToBounds = YES;
    self.headPortraitImageView.layer.cornerRadius = self.headPortraitImageView.frame.size.height / 2;
    
    
    self.userNameView = [[UIView alloc]initWithFrame:CGRectMake(ViewH / 3 * 2 + 5, 10, ViewW - (ViewH / 3 * 2 + 5),(ViewH / 3 * 2 - 15) / 2)];
//    self.userNameView.backgroundColor = [UIColor redColor];
    [self addSubview:self.userNameView];
    
    
    self.userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.userNameView.frame.size.width / 3 * 2, self.userNameView.frame.size.height)];
//    self.userNameLabel.backgroundColor = [UIColor greenColor];
    [self.userNameView addSubview:self.userNameLabel];
    self.userNameLabel.font = [UIFont systemFontOfSize:25];
    
    
    
    self.sexImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.userNameLabel.frame.size.width, 0, self.userNameView.frame.size.height, self.userNameView.frame.size.height)];
//    self.sexImageView.backgroundColor = [UIColor yellowColor];
    [self.userNameView addSubview:self.sexImageView];
    
    
    self.numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(ViewH / 3 * 2 + 5, (ViewH / 3 * 2 - 15) / 2 + 15, ViewW - (ViewH / 3 * 2 + 5), (ViewH / 3 * 2 - 15) / 4)];
//    self.numberLabel.backgroundColor = [UIColor purpleColor];
    [self addSubview:self.numberLabel];
    
    
    self.attentionButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.attentionButton.frame = CGRectMake(10, ViewH / 3 * 2 + 5, (ViewW - 30) / 2, ViewH / 3 - 15);
    self.attentionButton.backgroundColor = [UIColor blackColor];
    [self addSubview:self.attentionButton];
    self.attentionButton.layer.masksToBounds = YES;
    self.attentionButton.layer.cornerRadius = 5;
    
    [self.attentionButton addTarget:self action:@selector(attentionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.separateView = [[UIView alloc]initWithFrame:CGRectMake(0, ViewH - 1, ViewW, 1)];
    self.separateView.backgroundColor = [UIColor blackColor];
    [self addSubview:self.separateView];
    self.separateView.alpha = 0.5;
    
    
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    [self setBigModel:self.bigModel];
    
   
    
    
}

- (void)setBigModel:(ModuleFirst_UserHomePageModel *)bigModel{
    
    _bigModel = bigModel;
    
    [self.headPortraitImageView sd_setImageWithURL:[NSURL URLWithString:_bigModel.image] placeholderImage:[UIImage imageNamed:@"holderr"]];
    
    self.userNameLabel.text = _bigModel.name;
    //userNameLabel自适应高度
    self.userNameLabel.numberOfLines = 1;
    [self.userNameLabel sizeToFit];
    self.sexImageView.frame = CGRectMake(self.userNameLabel.frame.size.width, 0, self.userNameLabel.frame.size.height, self.userNameLabel.frame.size.height);
    
    if ([_bigModel.gender.stringValue isEqualToString:@"0"]) {
        self.sexImageView.image = [UIImage imageNamed:@"GirlImage"];
    }else{
        self.sexImageView.image = [UIImage imageNamed:@"BoyImage"];
    }
    
    NSString *count = _bigModel.trips_count.stringValue;
    self.numberLabel.text = [NSString stringWithFormat:@"%@篇游记",count];
    
}


- (void)attentionButtonAction:(UIButton *)isButton{
    
    
    
    
}





@end
